﻿using ServerInfra.Classes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using TalentDesk.Contracts.Ef;
using TalentDesk.Data;

namespace TalentDesk.WcfService
{
    internal class ProjectBaseClass : BusinessBase, IBusinessBase
    {

        private ObjectCtxManager TalentDeskContextManager
        {
            get
            {
                return GetObjectContext<TalentDeskEntities>("TalentDeskEntities");
            }
        }

        protected TalentDeskEntities TalentDeskContext
        {
            get
            {
                return TalentDeskContextManager.EFContext as TalentDeskEntities;
            }
        }


        public void BeginTransaction()
        {
           
                this.isRoot = TalentDeskContextManager.BeginTransaction();
            

        }
        public void CommitTransaction()
        {
            if (this.isRoot)
                TalentDeskContextManager.CommitTransaction();
        }

        public void RollbackTransaction()
        {
            if (this.isRoot)
                TalentDeskContextManager.RollbackTransaction();
        }


        protected TrackableCollection<T> ToTrackableCollection<T>(List<T> items)
        {
            TrackableCollection<T> trackableCollection = new TrackableCollection<T>();
            items.ForEach(t => trackableCollection.Add(t));
            return trackableCollection;
        }




    }
}